<?php

namespace App\Admin\Extensions;

use App\Model\UserProfile;
use Encore\Admin\Admin;

class RoleOp extends BaseAction
{
    protected function render()
    {
        Admin::script($this->script($this->actionUrl));
        $btn = $this->buildButton('fail', '取消女用户', ['id' => $this->id, 'status' => -1]);
        $blackbtn = $this->buildButton('fail', '加入黑名单', ['id' => $this->id, 'action' => 'blacklist']);
        $unblackbtn = $this->buildButton('ok', '取消黑名单', ['id' => $this->id, 'action' => 'remove_blacklist']);
        $clearbtn = $this->buildButton('ok', '设置默认头像', ['id' => $this->id, 'action' => 'default_avatar']);
        $recOkbtn = $this->buildButton('ok', '推荐', ['id' => $this->id, 'status' => 1, 'action' => 'rec']);
        $unrecbtn = $this->buildButton('fail', '不推荐', ['id' => $this->id, 'status' => 0, 'action' => 'rec']);
        $str = [];
        if ($this->row->role == UserProfile::ROLE_HOST) {
            $str[]  = $btn;
        }
        if (!in_array($this->row->user_id, $this->extra['black_hosts'])) {
            $str[] = $blackbtn;
        } else {
            $str[] = $unblackbtn;
        }
        if ($this->row->is_recommend == 0) $str[] = $recOkbtn;
        else $str[] = $unrecbtn;
        $str[] = $clearbtn;
        return implode('<br/><br/>', $str);
    }
}
